import Request from '@/libs/request'
import qs from 'qs'

/**查询所有角色 */
export const selectAllPlatFormRole = () =>
  Request.get<SysDict.Item[]>('/mg/selectAllPlatFormRole')

/**添加角色 */
export const addPlatFormRole = (data: {dictName: string; dictDesc: string}) =>
  Request.get<null>('/mg/addPlatFormRole', data)

/**修改角色 */
export const editPlatFormRole = (data: SysDict.EditItemDataSource) =>
  Request.get<null>('/mg/editPlatFormRole', data)

/**删除角色 */
export const deletePlatFormRole = (data: SysDict.DeleteItemDataSource) =>
  Request.get<null>('/mg/deletePlatFormRole', data)

//? administrator -----------------------------------
/**查询所有管理账号 */
export const mSelectPlatFormUserByPage = (
  data: {
    roleCode: RoleCode
    platFormUserName: PlatFormUserName
  } & Paging
) =>
  Request.get<PagingResponse<User.PlatForm>>(
    '/mg/mSelectPlatFormUserByPage',
    data
  )

/**添加管理账号 */
export const addPlatFormUser = (data: {
  platFormUserName: PlatFormUserName
  platFormUserPass: PlatFormUserPass
  platFormUserDesc: PlatFormUserDesc
  roleCode: RoleCode
}) => Request.get<null>('/mg/addPlatFormUser', data)

/**修改管理账号 */
export const editPlatFormUser = (data: {
  platFormUserDesc: PlatFormUserDesc
  platFormUserId: PlatFormUserId
  platFormUserName: PlatFormUserName
  roleCode: RoleCode
}) => Request.get<null>('/mg/editPlatFormUser', data)

/**删除管理账号 */
export const deletePlatFormUser = (data: {platFormUserId: PlatFormUserId}) =>
  Request.get<null>('/mg/deletePlatFormUser', data)

/**查询该角色已有的权限和没有的权限 */
export const selectRoleAuthByRoleCode = (data: {roleCode: RoleCode}) =>
  Request.get<User.RoleAuth>('/mg/selectRoleAuthByRoleCode', data)

/**修改角色权限 */
export const editRoleAuthByRoleCode = (data: {
  roleAuthId: RoleAuthId
  authFlag: AuthFlag
}) => Request.get<null>('/mg/editRoleAuthByRoleCode', data)

//? api -----------------------------------
/**查询所有接口 */
export const mSelectPlatFormAuthByPage = (
  data: {
    authName: AuthName
    roleCode: RoleCode
  } & Paging
) =>
  Request.get<PagingResponse<User.PlatFormAuth>>(
    '/mg/mSelectPlatFormAuthByPage',
    data
  )

/**添加接口 */
export const addPlatFormAuth = (data: User.AddPlatFormAuthDataSource) =>
  Request.get<null>('/mg/addPlatFormAuth', data)

/**修改接口 */
export const editPlatFormAuth = (data: User.EditPlatFormAuthDataSource) =>
  Request.get<null>('/mg/editPlatFormAuth', data)

/**删除接口 */
export const deletePlatFormAuth = (data: {authId: AuthId}) =>
  Request.get<null>('/mg/deletePlatFormAuth', data)

/**查询所有接口类型 */
export const selectAllAuthCate = () =>
  Request.get<SysDict.Item[]>('/mg/selectAllAuthCate')

//? 界面 -----------------------------------
//查询所有模块功能
export const selectAllPlatFormModule = () =>
  Request.get<User.InterfaceModule[]>('/mg/selectAllPlatFormModule')

//添加模块功能
export const addPlatFormModule = (data: User.AddInterfaceModuleDataSource) =>
  Request.post<null>('/mg/addPlatFormModule', qs.stringify(data))

//删除模块
export const deleteModule = (data: User.DeleteInterfaceModuleDataSource) =>
  Request.post<null>('/mg/deleteModule', qs.stringify(data))

//修改模块
export const editModule = (data: User.AddInterfaceModuleDataSource) =>
  Request.post<null>('/mg/editModule', qs.stringify(data))

//查询角色模块
export const selectRoleModule = (data: { roleCode: RoleCode }) =>
  Request.get<User.RoleInterfaceModule[]>('/mg/selectRoleModule', data)

//修改角色模块
export const editRoleModuleByRoleModuleId = (
  data: User.EditRoleInterFaceModuleDataSource
) => Request.post<null>('/mg/editRoleModuleByRoleModuleId', qs.stringify(data))

// //查询我的模块
// export const selectMyModule = (data) => Request.post<null>("/mg/selectMyModule", qs.stringify(data) );
